package com.reportgenerate.marketreport.service.implement;

import com.reportgenerate.marketreport.service.RowBoundsToPage;
import org.springframework.stereotype.Service;

/**
 * @program: reportgenerate
 * @Description: RowBoundsToPage的实现类
 * @author: Mr.Cheng
 * @Email: ccelephant_518@126.com
 * @date: 2023/8/20 19:55
 */
@Service
public class RowBoundsToPageImpl implements RowBoundsToPage {
    /**
     * @param page
     * @Description: page to offset
     * @Param: [page]
     * @return: java.lang.Integer
     * @Author: Mr.Cheng
     * @Email: ccelephant_518@126.com
     * @Date: 2023/8/20 19:53
     */
    @Override
    public Integer offset(Integer page, Integer size) {
        return (page - 1) * size;
    }

    /**
     * @param size
     * @Description: size to limit
     * @Param: [size]
     * @return: java.lang.Integer
     * @Author: Mr.Cheng
     * @Email: ccelephant_518@126.com
     * @Date: 2023/8/20 19:53
     */
    @Override
    public Integer limit(Integer size) {
        return size;
    }

    /**
     * @param offset
     * @param size
     * @Description: 获取页数
     * @Param: [offset, size]
     * @return: java.lang.Integer
     * @Author: Mr.Cheng
     * @Email: ccelephant_518@126.com
     * @Date: 2023/8/22 23:39
     */
    @Override
    public Integer getPage(Integer offset, Integer size) {
        if (offset != null && size != null) {
            return offset / size + 1;
        }
        return null;
    }
}
